﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.SysMenu.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.SysMenu;
/// <summary>
/// 添加系统菜单服务
/// </summary>
public class InsertSysMenuService : ApiBase<RequestInsertSysMenuModel>
{
    /// <summary>
    /// 系统菜单仓储
    /// </summary>
    public SysMenuRep sysMenuRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new SysMenuModel();

        model.MenuName = Parameter.MenuName;
        model.ParentId = Parameter.ParentId;
        model.OrderNum = Parameter.OrderNum;
        model.Path = Parameter.Path;
        model.Component = Parameter.Component;
        model.RouteParams = Parameter.RouteParams;
        model.IsFrame = Parameter.IsFrame;
        model.IsCache = Parameter.IsCache;
        model.MenuType = Parameter.MenuType;
        model.Visible = Parameter.Visible;
        model.Status = Parameter.Status;
        model.Perms = Parameter.Perms;
        model.Icon = Parameter.Icon;
        model.Remark = Parameter.Remark;
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;

        var res = sysMenuRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = sysMenuRep.GetSysMenuByMenuId(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

